package com.ncr.travel.appmgr.client.command;

import com.google.gwt.user.client.Command;
import com.ncr.nep.dashboardcore.rest.client.HTTPRequest;
import com.ncr.nep.dashboardcore.rest.client.JSONCallback;
import com.ncr.nep.dashboardcore.rest.client.MIMEType;
import com.ncr.travel.appmgr.client.service.AppManagerWebService;
import com.ncr.travel.appmgr.model.shared.ScreenConfiguration;

public class PostScreenConfigurationCommand implements Command {

	private final ScreenConfiguration screenConfig;
	private final AppManagerWebService webService;
	private final JSONCallback<ScreenConfiguration> callback;

	public PostScreenConfigurationCommand(ScreenConfiguration screenConfig, AppManagerWebService webService, JSONCallback<ScreenConfiguration> callback) {
		this.screenConfig = screenConfig;
		this.webService = webService;
		this.callback = callback;
	}

	@Override
	public void execute() {
//		String json = PiritiScreenConfiguration.WRITER.toJson(screenConfig);
		webService.doPost("/updateScreenConfigurationJson", new HTTPRequest()
			        .contentType(MIMEType.APPLICATION_JSON)
			        .accept(MIMEType.TEXT_PLAIN)
			        .data(screenConfig), callback);
	}

	public final ScreenConfiguration getScreenConfiguration() {
		return screenConfig;
	}

}
